/**
 * product管理初始化
 */
var BusPrductInfo = {
    id: "BusPrductInfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
BusPrductInfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '产品编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '产品编码', field: 'prdNo', visible: true, align: 'center', valign: 'middle'},
            {title: '企业编号', field: 'comId', visible: true, align: 'center', valign: 'middle'},
            {title: '企业名称', field: 'comName', visible: true, align: 'center', valign: 'middle'},
            {title: '产品名称', field: 'prdName', visible: true, align: 'center', valign: 'middle'},
            {title: '产品图片', field: 'prdImgFilePath', visible: true, align: 'center', valign: 'middle'
                ,formatter:function(value, row, index){
                return "<img style='width: 100px;height: 100px' src='"+value+"'>";
            }},
            {title: '产品描述', field: 'prdDesc', visible: true, align: 'center', valign: 'middle'},
            {title: '产品执行标准', field: 'prdGb', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createtime', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人', field: 'maintainer', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
BusPrductInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        BusPrductInfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加product
 */
BusPrductInfo.openAddBusPrductInfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加product',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/busPrductInfo/busPrductInfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看product详情
 */
BusPrductInfo.openBusPrductInfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'product详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/busPrductInfo/busPrductInfo_update/' + BusPrductInfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除product
 */
BusPrductInfo.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/busPrductInfo/delete", function (data) {
            Feng.success("删除成功!");
            BusPrductInfo.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("busPrductInfoId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询product列表
 */
BusPrductInfo.search = function () {
    var queryData = {};
    queryData['prdName'] = $("#condition").val();
    BusPrductInfo.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = BusPrductInfo.initColumn();
    var table = new BSTable(BusPrductInfo.id, "/busPrductInfo/list", defaultColunms);
    table.setPaginationType("client");
    BusPrductInfo.table = table.init();
});
